﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace EDTS.Weixin.Submits
{
    public class Department
    {
        /// <summary>
        /// 创建部门
        /// </summary>
        /// <param name="name"></param>
        /// <param name="parentID"></param>
        /// <returns></returns>
        public static int Create(string token,string name,int parentID)
        {
            var url = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
            var obj = new { name = name, parentid = parentID };
            var ret = Submit.Post(token, url, obj);
            return ret.Value<int>("id");
        }
        /// <summary>
        /// 更新部门
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="parentID"></param>
        public static void Update(string token, int id, string name, int parentID)
        {
            var url = "https://qyapi.weixin.qq.com/cgi-bin/department/update";
            var obj = new { id = id, name = name, parentid = parentID };
            Submit.Post(token, url, obj);
        }
        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="id"></param>
        public static void Delete(string token, int id)
        {
            var url = "https://qyapi.weixin.qq.com/cgi-bin/department/delete";
            var parameters = new List<KeyValuePair<string, string>>();
            parameters.Add(new KeyValuePair<string, string>("id", id.ToString()));
            Submit.Get(token, url, parameters);
        }
        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <returns></returns>
        public static JObject GetList(string token)
        {
            var url = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
            var ret = Submit.Get(token, url, null);
            return ret;
        }
    }
}
